package org.zjt.wordcnt.demo;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.Arrays;

/**
 * DESC
 *
 * @author
 * @create 2017-05-23 上午11:09
 **/
public class WordMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        Arrays.stream(value.toString().split(" ")).forEach(
                a -> {
                    try {
                        context.write(new Text(a), new IntWritable(1));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
        );
    }
}
